import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:untitled1/app/utils/utilJson.dart';

import '../../../../../res/myColors.dart';
import '../../../../../utils/utilRouter.dart';
import '../../../../../utils/utilScreen.dart';
import '../../../../../widgets/MyContainer.dart';
import '../../../../../widgets/dialog/MyBottomDialog.dart';
import '../../../../../widgets/dialog/MyBottomDialog2.dart';
import '../../../../../widgets/toast/MyToast.dart';
import '../../../../../bean/KeyValueBean.dart';
import 'ChargebackDialogPage.dart';
import 'EmployerPage_SalarySystemSelect.dart';
import 'EmployerPage_ServiceDialog.dart';
import 'EmployerPage_citySelect.dart';
import 'EmployerPage_workTypeSelect.dart';
import 'EmployerPage_workTypeSelect2.dart';
import 'EmployerPage_workTypeSelect3.dart';
import 'RadioDialogPage.dart';

//雇主弹出框
class EmployerPageDialog {
  static void dialog_citySelect(
    BuildContext context,
    final Function(List<KeyValueBean> list)? onConfirm,
  ) {
    MyBottomDialog.show(
      context: context,
      width: utilScreen.getScreenWidth(context),
      height: utilScreen.getScreenHeight(context) - 50,
      borderRadius: 5,
      // 👈 可设置为 0 取消圆角
      animationType: DialogAnimationType.slide,
      //底部划出
      builder:
          (ctx) => EmployerPage_citySelect(
            onConfirm: (data) {
              print(">]data 111111=${data}");
              onConfirm != null ? onConfirm(data) : null;
            },
          ),
    );
  }

  //工种和薪资
  static void dialog_workTypeSelect(
    BuildContext context,
    final Function(Map<String, List<KeyValueBean>> map)? onConfirm,
  ) {
    MyBottomDialog.show(
      context: context,
      width: utilScreen.getScreenWidth(context),
      height: utilScreen.getScreenHeight(context) - 50,
      borderRadius: 5,
      // 👈 可设置为 0 取消圆角
      animationType: DialogAnimationType.slide,
      //底部划出
      builder:
          (ctx) => EmployerPage_workTypeSelect(
            onConfirm: (data) {
              print(">]data 111111=${data}");
              onConfirm != null ? onConfirm(data) : null;
            },
          ),
    );
  }

  static void dialog_gongzhong(
      BuildContext context,
      List<KeyValueBean> valueList,
      final Function(KeyValueBean bean)? onConfirm,
      ) {
    // print(">]dialog_gongzhong valueList=${utilJson.listObjectToStr(valueList) }");
    MyBottomDialog.show(
      context: context,
      width: utilScreen.getScreenWidth(context),
      height: utilScreen.getScreenHeight(context) *0.7,
      borderRadius: 5,
      // 👈 可设置为 0 取消圆角
      animationType: DialogAnimationType.slide,
      //底部划出
      builder: (ctx) {
       return RadioDialogPage(
          valueList: valueList,
          onConfirm: (data) {
            print(">]data 111111=${data}");
            if(null!=onConfirm){
              onConfirm(data!);
            }
          },
        );
      },
    );
  }



  //退单
  static void dialog_Chargeback(
    BuildContext context,
    final Function(KeyValueBean bean)? onConfirm,
  ) {


    MyBottomDialog2.show(
      context: context,
      dialogWidth: MediaQuery.of(context).size.width ,
      height: utilScreen.getScreenHeight(context),
      animationType: DialogAnimationType.slide,
      avoidSoftInput: true, // ✅ 显示时自动适配键盘
      builder: (context) =>  ChargebackDialogPage(
        onConfirm: (data) {
          print(">]data 111111=${data}");
          onConfirm != null ? onConfirm(data) : null;
        },
      ),
    );
  }

  static void dialog_workTypeSelect_salarySystem(
    BuildContext context,
  ) {
    showGeneralDialog(
      context: context,
      barrierDismissible: true,
      barrierLabel: "Dialog",
      barrierColor: Colors.black54,
      transitionDuration: const Duration(milliseconds: 300),
      pageBuilder: (context, animation, secondaryAnimation) {
        return GestureDetector(
          onTap: () => FocusScope.of(context).unfocus(), // 点击外部关闭键盘
          child: Material(
            type: MaterialType.transparency,
            child: Align(
              alignment: Alignment.bottomCenter,
              child: Padding(
                padding: EdgeInsets.only(
                  bottom: MediaQuery.of(context).viewInsets.bottom, // 🧠 关键点：动态监听键盘高度
                  left: 16,
                  right: 16,
                  top: 40,
                ),
                child: SingleChildScrollView(
                  padding: const EdgeInsets.all(16),

                  child: Column(
                    children: [

                      Container(
                        height: 200,
                        color: Colors.red,
                        child: Text("选择排序方式"),
                      ),
                      Container(
                        color: Colors.blue,
                        child: Text("选择排序方式"),
                      ),
                      Container(
                        height: 200,
                        color: Colors.blue,
                        child:  TextField(
                          onChanged: (v){
                          },
                          expands: true,     // ⬅️ 关键点：填满父容器
                          maxLines: null,    // ⬅️ 必须为 null
                          minLines: null,    // ⬅️ 必须为 null
                          decoration: InputDecoration(
                            hintText: "请输入内容",
                            border: InputBorder.none,     // 去掉默认边框
                            contentPadding: EdgeInsets.all(10), // 设置内边距
                          ),),
                      ),

                    ]
                  ), // 包含 TextField 的自定义组件
                ),
              ),
            ),
          ),
        );
      },
    );

  }

  //雇主列表排序
  static void sort(BuildContext context, final Function(int type)? onConfirm) {
    Get.bottomSheet(
      Container(
        color: Colors.white,
        constraints: BoxConstraints(
          maxHeight: Get.height * 0.8, // 限制最大高度，避免超出
        ),
        child: SingleChildScrollView(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              ListTile(
                // leading: Icon(Icons.music_note),
                title: Text("按发布时间倒序"),
                onTap: () => onConfirm!(1),
              ),
              ListTile(
                // leading: Icon(Icons.video_call),
                title: Text("按发布时间升序"),
                onTap: () => onConfirm!(2),
              ),
              ListTile(
                // leading: Icon(Icons.video_call),
                title: Text("按入户时间倒序"),
                onTap: () => onConfirm!(3),
              ),
              ListTile(
                // leading: Icon(Icons.video_call),
                title: Text("按入户时间升序"),
                onTap: () => onConfirm!(4),
              ),
              ListTile(
                // leading: Icon(Icons.video_call),
                title: Text("按预算薪资倒序"),
                onTap: () => onConfirm!(5),
              ),
              ListTile(
                // leading: Icon(Icons.video_call),
                title: Text("按预算薪资升序"),
                onTap: () => onConfirm!(6),
              ),
              ListTile(
                // leading: Icon(Icons.close),
                title: Text("取消"),
                onTap: () => Get.back(), // 正确方式是关闭弹窗
              ),
            ],
          ),
        ),
      ),
      backgroundColor: Colors.white,
      isDismissible: true,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
      ),
      isScrollControlled: true, // 允许内容撑满后滚动
    );
  }

  //辅助工种
  static void dialog_workTypeSelect2(
    BuildContext context,
    final Function(List<KeyValueBean> list)? onConfirm,
  ) {
    MyBottomDialog.show(
      context: context,
      width: utilScreen.getScreenWidth(context),
      height: utilScreen.getScreenHeight(context) - 50,
      borderRadius: 5,
      // 👈 可设置为 0 取消圆角
      animationType: DialogAnimationType.slide,
      //底部划出
      builder:
          (ctx) => EmployerPage_workTypeSelect2(
            onConfirm: (data) {
              print(">]data 111111=${data}");
              onConfirm != null ? onConfirm(data) : null;
            },
          ),
    );
  }

  //薪酬
  static void dialog_workTypeSelect3(
    BuildContext context,
    final Function(List<KeyValueBean> list)? onConfirm,
  ) {
    MyBottomDialog.show(
      context: context,
      width: utilScreen.getScreenWidth(context),
      height: utilScreen.getScreenHeight(context) - 50,
      borderRadius: 5,
      // 👈 可设置为 0 取消圆角
      animationType: DialogAnimationType.slide,
      //底部划出
      builder:
          (ctx) => EmployerPage_workTypeSelect3(
            onConfirm: (data) {
              print(">]data 111111=${data}");
              onConfirm != null ? onConfirm(data) : null;
            },
          ),
    );
  }

  //薪酬类型
  static void salaryType(
    BuildContext context,
    final Function(int type)? onConfirm,
  ) {
    Get.bottomSheet(
      Container(
        color: Colors.white,
        constraints: BoxConstraints(
          maxHeight: Get.height * 0.8, // 限制最大高度，避免超出
        ),
        child: SingleChildScrollView(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              ListTile(
                leading: Icon(Icons.music_note),
                title: Text("年薪"),
                onTap: () => onConfirm!(1),
              ),
              ListTile(
                leading: Icon(Icons.video_call),
                title: Text("月薪"),
                onTap: () => onConfirm!(2),
              ),
              ListTile(
                leading: Icon(Icons.video_call),
                title: Text("时新"),
                onTap: () => onConfirm!(3),
              ),

              ListTile(
                leading: Icon(Icons.close),
                title: Text("取消"),
                onTap: () => Get.back(), // 正确方式是关闭弹窗
              ),
            ],
          ),
        ),
      ),
      backgroundColor: Colors.white,
      isDismissible: true,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
      ),
      isScrollControlled: true, // 允许内容撑满后滚动
    );
  }

  //薪酬制度
  static void salarySystem(
    BuildContext context,
    final Function(KeyValueBean? bean)? onConfirm,
  ) {
    MyBottomDialog.show(
      context: context,
      width: utilScreen.getScreenWidth(context),
      height: utilScreen.getScreenHeight(context) * 0.6,
      borderRadius: 5,
      // 👈 可设置为 0 取消圆角
      animationType: DialogAnimationType.slide,
      //底部划出
      builder:
          (ctx) => EmployerPage_SalarySystemSelect(
            onConfirm: (data) {
              print(">]data 111111=${data}");
              if (onConfirm != null) {
                onConfirm(data);
              }
            },
          ),
    );
  }

  //工作属性
  static void workAttributes(
    BuildContext context,
    final Function(int type)? onConfirm,) {
    Get.bottomSheet(
      Container(
        color: Colors.white,
        constraints: BoxConstraints(
          maxHeight: Get.height * 0.8, // 限制最大高度，避免超出
        ),
        child: SingleChildScrollView(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              ListTile(
                leading: Icon(Icons.music_note),
                title: Text("住家"),
                onTap: () => onConfirm!(1),
              ),
              ListTile(
                leading: Icon(Icons.video_call),
                title: Text("白班"),
                onTap: () => onConfirm!(2),
              ),
              ListTile(
                leading: Icon(Icons.video_call),
                title: Text("钟点工"),
                onTap: () => onConfirm!(3),
              ),
              ListTile(
                leading: Icon(Icons.video_call),
                title: Text("夜班"),
                onTap: () => onConfirm!(3),
              ),
              ListTile(
                leading: Icon(Icons.close),
                title: Text("关闭"),
                onTap: () => Get.back(), // 正确方式是关闭弹窗
              ),
            ],
          ),
        ),
      ),
      backgroundColor: Colors.white,
      isDismissible: true,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
      ),
      isScrollControlled: true, // 允许内容撑满后滚动
    );
  }

  //服务时间
  static void servicingTime(
      BuildContext context,
      final Function(KeyValueBean bean)? onConfirm,
      ) {
    MyBottomDialog.show(
      context: context,
      width: utilScreen.getScreenWidth(context),
      height: utilScreen.getScreenHeight(context)*0.6,
      borderRadius: 5,
      // 👈 可设置为 0 取消圆角
      animationType: DialogAnimationType.slide,
      //底部划出
      builder:
          (ctx) => EmployerPage_ServiceDialog(
        onConfirm: (data) {
          print(">]data 111111=${data}");
          // onConfirm != null ? onConfirm(data) : null;
        },
      ),
    );
  }
  //来源
  static showSource(){
    Get.bottomSheet(
      Container(
        color: Colors.white,
        height: 250,
        child:SingleChildScrollView(
          child:Column(
            children: [
              ListTile(
                leading: Icon(Icons.music_note),
                title: Text("平台线上"),
                onTap: () => Get.back(),
              ),
              ListTile(
                leading: Icon(Icons.video_call),
                title: Text("平台线下"),
                onTap: () => Get.back(),
              ),
              ListTile(
                leading: Icon(Icons.video_call),
                title: Text("个人"),
                onTap: () => Get.back(),
              ),
              ListTile(
                leading: Icon(Icons.video_call),
                title: Text("取消"),
                onTap: () => Get.back(),
              ),
            ],
          ) ,
        ) ,
      ),
      backgroundColor: Colors.white,
      isDismissible: true,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
      ),
    );

  }
//分类
  static showClassification(){
    Get.bottomSheet(
      Container(
        color: Colors.white,
        height: 250,
        child:SingleChildScrollView(
          child:Column(
            children: [
              ListTile(
                leading: Icon(Icons.music_note),
                title: Text("B端"),
                onTap: () => Get.back(),
              ),
              ListTile(
                leading: Icon(Icons.video_call),
                title: Text("C端"),
                onTap: () => Get.back(),
              ),
              ListTile(
                leading: Icon(Icons.video_call),
                title: Text("取消"),
                onTap: () => Get.back(),
              ),
            ],
          ) ,
        ) ,
      ),
      backgroundColor: Colors.white,
      isDismissible: true,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
      ),
    );

  }

  //民族
  static void showNationality(){
    Get.bottomSheet(
      Container(
        color: Colors.white,
        height: 350,
        child:SingleChildScrollView(
          child:Column(
            children: [
              ListTile(
                leading: Icon(Icons.music_note),
                title: Text("汉族"),
                onTap: () => Get.back(),
              ),
              ListTile(
                leading: Icon(Icons.video_call),
                title: Text("回族"),
                onTap: () => Get.back(),
              ),
              ListTile(
                leading: Icon(Icons.video_call),
                title: Text("藏族"),
                onTap: () => Get.back(),
              ),
              ListTile(
                leading: Icon(Icons.video_call),
                title: Text("维吾尔族"),
                onTap: () => Get.back(),
              ),ListTile(
                leading: Icon(Icons.video_call),
                title: Text("蒙古族"),
                onTap: () => Get.back(),
              ),ListTile(
                leading: Icon(Icons.video_call),
                title: Text("取消"),
                onTap: () => Get.back(),
              ),
            ],
          ) ,
        ) ,
      ),
      backgroundColor: Colors.white,
      isDismissible: true,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
      ),
    );

  }
  //宗教信仰
  static void showReligion(){
    Get.bottomSheet(
      Container(
        color: Colors.white,
        height: 350,
        child:SingleChildScrollView(
          child:Column(
            children: [
              ListTile(
                leading: Icon(Icons.music_note),
                title: Text("佛教"),
                onTap: () => Get.back(),
              ),
              ListTile(
                leading: Icon(Icons.video_call),
                title: Text("道教"),
                onTap: () => Get.back(),
              ),
              ListTile(
                leading: Icon(Icons.video_call),
                title: Text("伊斯兰教"),
                onTap: () => Get.back(),
              ),
              ListTile(
                leading: Icon(Icons.video_call),
                title: Text("基督教"),
                onTap: () => Get.back(),
              ),ListTile(
                leading: Icon(Icons.video_call),
                title: Text("取消"),
                onTap: () => Get.back(),
              ),
            ],
          ) ,
        ) ,
      ),
      backgroundColor: Colors.white,
      isDismissible: true,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
      ),
    );

  }
  //性别要去
  static void showSex(){
    Get.bottomSheet(
      Container(
        color: Colors.white,
        height: 200,
        child:SingleChildScrollView(
          child:Column(
            children: [
              ListTile(
                leading: Icon(Icons.music_note),
                title: Text("男"),
                onTap: () => Get.back(),
              ),
              ListTile(
                leading: Icon(Icons.video_call),
                title: Text("女"),
                onTap: () => Get.back(),
              ),ListTile(
                leading: Icon(Icons.video_call),
                title: Text("取消"),
                onTap: () => Get.back(),
              ),
            ],
          ) ,
        ) ,
      ),
      backgroundColor: Colors.white,
      isDismissible: true,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
      ),
    );

  }
  //年龄
  static void showAge(BuildContext context){
    Get.bottomSheet(
      Container(
        color: Colors.white,
        height: 700,
        child:SingleChildScrollView(
          child:Column(
            children: [
              ListTile(
                leading: Icon(Icons.music_note),
                title: Text("不限"),
                onTap: () => Get.back(),
              ),
              ListTile(
                leading: Icon(Icons.video_call),
                title: Text("35以下"),
                onTap: () => Get.back(),
              ),ListTile(
                leading: Icon(Icons.video_call),
                title: Text("36-40"),
                onTap: () => Get.back(),
              ),ListTile(
                leading: Icon(Icons.video_call),
                title: Text("31-45"),
                onTap: () => Get.back(),
              ),ListTile(
                leading: Icon(Icons.video_call),
                title: Text("46-50"),
                onTap: () => Get.back(),
              ),ListTile(
                leading: Icon(Icons.video_call),
                title: Text("50以上"),
                onTap: () => Get.back(),
              ),ListTile(
                leading: Icon(Icons.video_call),
                title: Text("关闭"),
                onTap: () => Get.back(),
              ),
            ],
          ) ,
        ) ,
      ),
      backgroundColor: Colors.white,
      isDismissible: true,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
      ),
    );

  }
  //年龄
  static void showEducation (){
    Get.bottomSheet(
      Container(
        color: Colors.white,
        height: 700,
        child:SingleChildScrollView(
          child:Column(
            children: [
              ListTile(
                leading: Icon(Icons.music_note),
                title: Text("不限"),
                onTap: () => Get.back(),
              ),
              ListTile(
                leading: Icon(Icons.video_call),
                title: Text("初中以上"),
                onTap: () => Get.back(),
              ),ListTile(
                leading: Icon(Icons.video_call),
                title: Text("高中以上"),
                onTap: () => Get.back(),
              ),ListTile(
                leading: Icon(Icons.video_call),
                title: Text("中专以上"),
                onTap: () => Get.back(),
              ),ListTile(
                leading: Icon(Icons.video_call),
                title: Text("大专以上"),
                onTap: () => Get.back(),
              ),ListTile(
                leading: Icon(Icons.video_call),
                title: Text("本科以上"),
                onTap: () => Get.back(),
              ),ListTile(
                leading: Icon(Icons.video_call),
                title: Text("研究生以上"),
                onTap: () => Get.back(),
              ),ListTile(
                leading: Icon(Icons.video_call),
                title: Text("关闭"),
                onTap: () => Get.back(),
              ),
            ],
          ) ,
        ) ,
      ),
      backgroundColor: Colors.white,
      isDismissible: true,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
      ),
    );

  }

}
